package org.datastructure.firstday.hashtable;

public class EmpLinkedList {

    public Employees head;


    public void addEmp(Employees employees) {
        if (head == null) {
            head = employees;
            return;
        }

        Employees current = head;
        while (true) {
            if (current.next == null) {
                break;
            }
            current = current.next;
        }
        current.next = employees;

    }

    public void list(int no) {
        if (head == null) {
            System.out.println("第 " + (no + 1) + " 链表为空");
            return;
        }

        Employees current = head;
        while (true) {
            System.out.printf(" => id=%d name=%s\t", current.id, current.name);
            if (current.next == null) {
                break;
            }
            current = current.next;
        }
        System.out.println();
    }

    public Employees getEmployee(int id) {
        if (head != null) {
            Employees current = head;

            while (true) {

                if (current.id == id) {
                    return current;
                }
                if (current.next == null) {
                    break;
                }
                current = current.next;
            }
        }
        return null;
    }

}
